class Stick implements Constraint{
 private Sphere c1;
 private Sphere c2;
 private float distance;
  private boolean dibujar;
  private boolean estado=false;
 
 
 public Stick(Sphere c1, Sphere c2,boolean dibujar){
   this.c1=c1;
   this.c2=c2;
   this.distance=c1.getVector().dist(c2.getVector());
   this.dibujar=dibujar;
 }
 
 public Stick(Sphere c1, Sphere c2,boolean dibujar,float distancia){
   this.c1=c1;
   this.c2=c2;
   this.distance=distancia;
   this.dibujar=dibujar;
   this.estado=true;
 }
 
 

 
 public boolean apply(){
  PVector x1 = c1.getVector();
  PVector x2 = c2.getVector(); 
  
  float dista =x1.dist(x2); //sqrt(pow(x1.x -x2.x,2)+pow(x1.y-x2.y,2)+pow(x1.z-x2.z,2));
  float dx = x1.x-x2.x;
  float dy = x1.y-x2.y;
  float dz = x1.z-x2.z;
  
  float diff = dista-distance;
  diff = diff/distance;
  
  dx=dx*0.5;
  dy=dy*0.5;
  dz=dz*0.5;
  //if(!c1.isPinned())
  if(!estado)
  c1.setPosicion(new PVector(x1.x -(diff*dx),x1.y -(diff*dy),x1.z -(diff*dz)));
  //if(!c2.isPinned())
  c2.setPosicion(new PVector(x2.x +(diff*dx),x2.y +(diff*dy),x2.z +(diff*dz)));
  return true;
 }
 
 public void draw(){
  
  if(dibujar){
   fill(255);
   stroke(255);
   strokeWeight(1);
   line(c1.getX(),c1.getY(),c1.getZ(),c2.getX(),c2.getY(),c2.getZ());
   strokeWeight(1);
   stroke(0);}
 }
 public Sphere gets1(){
   return c1;
 }
 public Sphere gets2(){
   return c2;
 }
}
